<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<LINK type="text/css" rel="stylesheet" href="${ctx}/css/style.css"/>
<script type="text/javascript" src="${ctx}/js/xtable.js"></script>
<script type="text/javascript" src="${ctx}/js/xtree.js"></script>
<script type="text/javascript" src="${ctx}/js/validator.js"></script>
<script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
<script type="text/javascript" src="${ctx}/dwr/util.js"></script>
<script type='text/javascript' src='${ctx}/dwr/interface/SecurityService.js'></script>
<script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
  <body onload="getApplicationPage()">
  <center>
      <form id="applicationForm">
      <table style="width:500px">
          <tr>
              <td>
                                                                 应用名称
              </td>
              <td>
                  <input type="text" name="applicationName" id="applicationName" elname="应用名称" required="1" maxLen="100"/>
              </td>
              <td>
                  <img src="${ctx}/images/common/button_select.jpg" title="查询应用" style="cursor:pointer" onclick="getApplicationPage()"/>
                  <img src="${ctx}/images/common/button_insert.jpg" title="添加应用" style="cursor:pointer" onclick="insertApplication()"/>
                  <img src="${ctx}/images/common/button_update.jpg" title="修改应用" style="cursor:pointer" onclick="updateApplication()"/>
                  <img src="${ctx}/images/common/button_delete.jpg" title="删除应用" style="cursor:pointer" onclick="deleteApplication()"/>
              </td>
          </tr>
      </table>
      </form>
  </center>
  <SCRIPT LANGUAGE="JavaScript" >
  var applicationThead = new Array(
  new XThead("选择", "radio"),
  new XThead("应用编号"),
  new XThead("应用名称")
  );

  var applicationXTable = new XTable("application", applicationThead);

  applicationXTable.XTbodyArray = function (model) {
      var array = new Array(
      new XTbody("application", model.applicationId, "radio", "onclick='setApplication(this)'", model),
      new XTbody("application", model.applicationId),
      new XTbody("application", model.applicationName)
      );
      return array;
  }
    
  applicationXTable.getXList = function (page){
      var application = new dwr.util.getValues("applicationForm");
      application.pageIndex = page;
      application.pageSize = applicationXTable.pageSize;
      SecurityService.selectApplicationList(application, function(list){applicationXTable.addTable(list);});
  }

  function getApplicationPage(){
      var application = dwr.util.getValues("applicationForm");
      SecurityService.selectApplicationNum(application, function(num){applicationXTable.setTotalPage(num);}) ;
  }
  </SCRIPT>
  </body>
</html>
<script>
function setApplication(obj){
    var application = obj.parentElement.parentElement.model;
    dwr.util.setValue("applicationName", application.applicationName);
}

function insertApplication(){
    var _form = $("applicationForm");

    if(!validate(_form)){
        return false;
    }
    var application = dwr.util.getValues("applicationForm");
    SecurityService.insertApplication(application, getApplicationPage);
}

function updateApplication(){
    var _form = $("applicationForm");

    if(!validate(_form)){
        return false;
    }
    var applicationId = applicationXTable.getRadioValue();
    var application = dwr.util.getValues("applicationForm");
    application.applicationId = applicationId;
    SecurityService.updateApplication(application, getApplicationPage);
}

function deleteApplication(){
    var applicationId = applicationXTable.getRadioValue();
    var application = new Application();
    application.applicationId = applicationId;
    SecurityService.deleteApplication(application, getApplicationPage);
}

</script>
